﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Gatheshop.Common;

namespace Gatheshop.Web.admin.giftcard
{
    public partial class list : Web.UI.ManagePage
    {
       
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ChkAdminLevel("giftcard", GEShopEnums.ActionEnum.Edit.ToString()); //检查权限
                dbind();
            }
        }
        public void dbind()
        {
            BLL.gift_card bll = new BLL.gift_card();
            DataTable dt = bll.getCardList();
            this.GridView_list.DataSource = dt;
            this.GridView_list.DataBind();
        }

        protected void GridView_list_RowCommand(object sender, GridViewCommandEventArgs e)
        {

            int rowIndex = Convert.ToInt32(e.CommandArgument);
            if (rowIndex > -1)
            {
                if (e.CommandName == "del")
                {
                string id = this.GridView_list.DataKeys[rowIndex].Value.ToString();

                    BLL.gift_card bll = new BLL.gift_card();

                    Boolean IsSuccess = bll.delete(id);
                    Type cstype = this.GetType();
                    if (IsSuccess == true)
                    {
                        ClientScript.RegisterStartupScript(cstype, "key", "<script>window.alert('删除成功！');window.location.href=window.location.href;</script>");
                    }
                    else
                    {
                        ClientScript.RegisterStartupScript(cstype, "key", "<script>window.alert('删除失败！');</script>");
                    }
                }
               

            }
        }

        protected void GridView_list_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)//判断是不是数据行
            {
                //当鼠标停留时更改背景色
                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#abcdef'");
                //当鼠标移开时还原背景色
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
                if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
                {
                    Button btdel = e.Row.Cells[8].Controls[0] as Button;
                    btdel.Attributes.Add("onclick", "javascript:if( confirm('确定删除?')){}else{return false;}");
                }
            }
        }

        protected void GridView_list_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.GridView_list.PageIndex = e.NewPageIndex;
            dbind();
        }
    }
}